package com.lakers.notice.springboot.model;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
 * 功能描述: NoticeSingleMessage
 * 点发消息
 * @author liqin(zxl)
 * @date 2024/5/3
 */
@Data
public class NoticeSendMessage {


    /**
     * 发送方
     */
    private NoticeUserInfo sender;

    /**
     * 接收者id列表(群成员列表,为空则不会推送)
     */
    private List<String> recvIds = new LinkedList<>();



    /**
     * 接收者终端类型,默认全部
     */
    private List<Integer> recvTerminals = NoticeTerminalType.codes();


    /**
     * 消息内容
     */
    private String content;


    /**
     * 通知消息关联的业务ID
     */
    private String businessId;


    /**
     * 通知消息关联的业务类型
     */
    private String businessType;

    /**
     * 消息类型
     * @see NoticeType
     */
    private Integer type;


    public void validation(){
        if (Objects.isNull(sender)) {
            throw new RuntimeException("通知发送人为空");
        }
        if ( StrUtil.isEmpty(sender.getUserId())){
            throw new RuntimeException("通知发送人编号为空");
        }
        if ( Objects.isNull(sender.getTerminal())){
            throw new RuntimeException("通知发送设备类型为空");
        }
        if ( CollectionUtils.isEmpty(recvIds)){
            throw new RuntimeException("接受人编号为空");
        }
        if ( CollectionUtils.isEmpty(recvTerminals)){
            throw new RuntimeException("接受设备类型为空");
        }
        if ( StrUtil.isEmpty(content)){
            throw new RuntimeException("通知内容为空");
        }
        if ( StrUtil.isEmpty(businessType)){
            throw new RuntimeException("通知关联业务类型为空");
        }
        if ( StrUtil.isEmpty(businessId)){
            throw new RuntimeException("通知关联业务编号为空");
        }
        if (Objects.isNull(type)) {
            throw new RuntimeException("消息类型为空");
        }

    }
}
